﻿@page
@model PersonModel
@using Microsoft.Extensions.Configuration;
@using Microsoft.Extensions.Logging;
@using System.Data.SqlClient;
@using Microsoft.AspNetCore.Http;
@using Microsoft.Extensions.Primitives;
@using System.Text.RegularExpressions;
@using System.Text.Json;
@using System.Linq;
@using reportWeb.Pages;
@using Microsoft.AspNetCore.Authentication.Cookies;
@using Microsoft.AspNetCore.Authorization;
@using Microsoft.AspNetCore.Authentication;
@using Microsoft.AspNetCore.Authentication.JwtBearer;
@functions{

    [IgnoreAntiforgeryToken(Order = 2000)]
    public class PersonModel : ReportModel
    {

        public PersonModel(IConfiguration configuration, ILogger<ReportModel> logger, ScopedObj scopedObj) : base(configuration, logger, scopedObj)
        {
        }
        protected override bool pre_page_load(IDictionary<Object, Object> before_exec_result = null)
        {
            var exprFaced = reportDefineForWeb.CurrentReportDefine.getEnv().getExprFaced();
            string worker_no = reportWeb.Controllers.UserController.ValidateJwtToken(HttpContext, HttpContext.Request.Cookies["access_token"])?.userid
                ?? HttpContext.Request.Cookies["worker_no"]
                ?? HttpContext.Request.Headers["worker_no"];

            var test_members = new HashSet<String>(rpt_group.members.Split(","));
            test_members.Add(rpt_group.owner);
            if (test_members.Contains(worker_no))
            {
                return true;
            }
            var _test_user_ = exprFaced.getVariable("_test_user_");
            if (_test_user_ != null)
            {
                test_members.addAll(_test_user_.ToString().Split(","));
            }
            if (test_members.Contains(worker_no) && reportDefineForWeb.CurrentReportDefine.getEnv().LastWriteTime < DateTime.Now.AddDays(-2))
            {
                return true;
            }
            throw new Exception("非法用户！" + worker_no);
        }
    }
}
@{
    Layout = null;
    await Model.Page_Load();
}
